<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>井下地图</title>
<!--	<script src="layui-v2.5.7/layui/layui.all.js"></script>-->
<!--	<script src="layui-v2.5.7/layui/layui.js"></script>-->
<!--	<link rel="stylesheet" href="layui-v2.5.7/layui/css/layui.css">-->

	<script src="js/GStarSDK.js"></script>
    <style>

	</style>

	<style>
		html,
		body {
			height: 100%;
			margin: 0;
			padding: 0;
		}

		.toolbar {
			height: 60px;
		}

		#webcad {
			width: 100%;
			/*height: calc(100% - 60px);*/
			height: calc(100% - 1px);
		}

		#modal,
		#modalstamp {
			position: fixed;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			background: rgba(2, 5, 1, 0.5);
			z-index: 200;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		#modal section,
		#modalstamp section {
			/*width: 300px;*/
			/*height: 300px;*/
			background-color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.GStarSDK-texture-image.stamp {
			width: 40px;
			height: 40px;
		}

		/* 自定义弹框啥的内容 */
		#div1 {
			background-color:#0e67bb;
			/*box-shadow: -10px 0px 80px #2C58A6 inset, !*左边阴影*! 10px 0px 15px #2C58A6 inset;*/
			/*background-image: url("../images/gz.png");*/
			background-repeat:repeat;
			border-radius: 8px;
			padding: 3px 3px;
			box-shadow: inset 0 0 30px #07417a;
		}
		#gasTable_tbody{
			 color: white;
		 }
		#gasTable_tbody tr td{
			padding: 3px 3px;
		}

		/*.GStarSDK{*/
		/*	background-color: #0e67bb;*/
		/*}*/
		.GStarSDK-note-bottom-info{
			display: none;
		}
		/*.GStarSDK-pc-toolsbar{*/
		/*	display: none;*/
		/*}*/
		.GStarSDK-func-btn-notes, .GStarSDK-func-btn-measures
		{
			display: none;
		}
		.GStarSDK-division GStarSDK-func-btn-save
		{
			display: none;
		}
		.GStarSDK-pc-toolsbar-floatbar
		{
			display: none;
		}

		/* 隐藏 加载笔图标*/
		.GStarSDK-progress img{
			display: none;
		}
		.GStarSDK-texture-image.stamp{
			width: 60px;
			height: 80px;
		}
		.GStarSDK-func-btn-layout{
			display: none !important;
		}
		.GStarSDK-func-btn-layer{
			display: none !important;
		}
	</style>
	<script src="../js/jquery.min.js"></script>
	<script src="data/webData.js"></script>
	<script src="js/jquery-3.1.1.min.js"></script>
	<script src="dropdown.js"></script>
	<link rel="stylesheet" href="dropdown.css">
	<link rel="stylesheet" href="layui-v2.6.8/layui/css/layui.css">
	<script src="layui-v2.6.8/layui/layui.js"></script>
	<script type="text/javascript">
		$(function () {
			//$(".GStarSDK-pc-toolsbar-floatbar")[0].style.display="none";
			//$(".GStarSDK-pc-toolsbar-list li")[0].style.display="none";
		})
	</script>
</head>
<body>

<div style="display:none; position: absolute; z-index: 9999999999; bottom: 10px;right: 5px;" id="div_menu" >
	<span onclick="showMenu()"> >> </span>
	<div class="layui-anim layui-anim-up" id="div_menuContent">
		<table>
			<tr>
				<td>&nbsp;<button type="button"  data-type="warning"   onclick="showWarningList(this)" class="layui-btn layui-btn-danger  layui-btn-sm">今日报警</button></td>
				<td>&nbsp;<button type="button"  data-type="warning"   onclick="showJinRiDaiBan(this)" class="layui-btn layui-btn-warm  layui-btn-sm">今日代办</button></td>
				<td>&nbsp;<button type="button" data-type="all"       onclick="showAllLocation(this)" id="btn_all_address"  class="layui-btn  layui-btn-sm">设备管理</button></td>
				<td>&nbsp;<button type="button"  data-type="href"      onclick="showReportList(this)" style="background-color: #0088bb;" class="layui-btn  layui-btn-sm">报表数据</button></td>
				<td>&nbsp;<button type="button"  data-type="href"      onclick="showTargetDataServer(this)" class="layui-btn layui-btn-normal  layui-btn-sm">数据管理</button></td>
                <td>
					<button type="button" class="layui-btn layui-btn-sm demolist" data-id="111" style="margin-left: 2px;">更多操作</button>
				</td>
				<td>
					<img src="../images/maxForm2.png" style="width: 20px; height: 20px; padding: 2px;"  onclick="window.open(location.href);">
				</td>
				<!--			 <td>&nbsp;<button type="button" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm">正常地点</button></td>-->
				<!--				 <td>&nbsp;<button type="button"  data-type="err"       onclick="showAllLocation(this)" id="btn_device_err" class="layui-btn layui-btn-warm layui-btn-radius layui-btn-sm">异常地点</button></td>-->
				<!--				 <td>&nbsp;<button type="button"  data-type="battery"       onclick="showBatteryInfo(this)" id="btn_device_battery" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm">电源模块</button></td>-->
				<!--				 <td> <button type="button"  data-type="showWangGe" onclick="showMapWanGeInfo(this)" class="layui-btn   layui-btn-radius layui-btn-sm">显示网格</button></td>-->
				<!--				 <td> <button type="button"  data-type="showEdit" onclick="showEditMapInfo(this)" class="layui-btn   layui-btn-radius layui-btn-sm">编辑模式</button></td>-->
			</tr>
		</table>
	</div>
</div>

<!--<div style="">-->
<!--	<div id="xy" style="color: red; " >-->

<!--	</div>-->
<!--	<button type="button" onclick="noteshow()">加载批注</button>-->
<!--	<button type="button" onclick="showSelectNoteInfo(1)">显示选中信息的详情</button>-->
<!--	<button type="button" onclick="showSelectNoteInfo2()">显示选中信息的详情2</button>-->
<!--</div>-->
<div id="webcad"></div>




<div id="modal" style="display: none;">
	<div style="float: left;color: #fff;" onclick="showSelectNoteInfo(0)" ><img src="../images/s_ico3.png"/> </div>

	<section id="div1" style="background-color: #0C0C0C;">
		<table class="hovertable" id="gasTable">
			<thead>
				<td colspan="3" style="font-weight: bold; font-size: 20px; color: #fade4a;" id="table_data_location"></td>
				<td style="display: none" id="table_data_pid"></td>
			</thead>
			<tbody id="gasTable_tbody">
					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td >甲烷</td><td id="table_data_CH4">0.00</td><td>%</td>
					</tr>
					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td >二氧化碳</td><td id="table_data_CO2">0.00</td><td>%</td>
					</tr>
					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td>一氧化碳</td><td id="table_data_CO">0</td><td >ppm</td>
					</tr>
					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td>温度</td><td  id="table_data_T">0.0</td><td>℃</td>
					</tr>
					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td>湿度</td><td  id="table_data_H">0.0</td><td>RH</td>
					</tr>

					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td>氧气</td><td id="table_data_O2">20.9</td><td >%</td>
					</tr>
					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td>烟感</td><td id="table_data_YANGAN">正常</td><td ></td>
					</tr>
					<tr onmouseover="this.style.backgroundColor='#6dc6ff';" onmouseout="this.style.backgroundColor='#07417a';">
						<td>&nbsp;
						 最新上数时间：
						</td>
						<td id="table_data_lastuploadtime">

						</td>
						<td></td>
					</tr>
			</tbody>
		</table>
	</section>
</div>

<div id="modalstamp" style="display: none;">
	<section>
		<p>这块是上层自定义的逻辑</p>
		<input id="inputstamp" type="text" />
		<button id="stampok">确定</button>
	</section>
</div>

</body>


	<script type="text/javascript">
	layui.use('dropdown', function(){
		var dropdown = layui.dropdown,$ = layui.jquery;

		dropdown.render({
			elem: '.demolist'
			,data: [{
				title: '获取坐标'
				,id: 'showRobotPosition'
			}, {
				title: '显示/隐藏CAD菜单'
				,id: 'showCADMenu'
			},{
				title: '初始化全部坐标'
				,id: 'InitializePosition'
			},{
				title: '最大化图纸'
				,id: 'showMaxCAD'
			}]
			,click: function(data, othis){
				var elem = $(this.elem)
						,listId = elem.data('id'); //表格列表的预埋数据
				if(data.id=="showRobotPosition"){
					//显示获取CAD坐标工具
					gstarSDK.func.measures.measureCoordinate.main();
					return;
				}
				if(data.id=="showCADMenu"){
					if($(".GStarSDK-pc-toolsbar").is(":hidden")){
						$(".GStarSDK-pc-toolsbar").show();
					}else{
						$(".GStarSDK-pc-toolsbar").hide();
					}

					return;
				}
				if(data.id=="InitializePosition"){
					let dataList=sensorServer.getSensorList({"page":1,"rows":1000});
					if(dataList==undefined||dataList==null)
					{
						alert("初始化LED设备失败！");
						return "[]";
					}
					let sensorList=dataList.data;

					const worldPos = gstarSDK.screen2World({x:100, y: 100});
					let x=parseFloat(worldPos.x.toFixed(2));
					let y=parseFloat(worldPos.y.toFixed(2));
					let z=0;

					for (let i = 0; i < sensorList.length; i++) {
						let sensorPid = sensorList[i].pid;
						let postData = {"ledPid": "0", "sensorPid": sensorPid, "x": x, "y": y, "z": z};
						sensorServer.updateCoordinate(postData);
					}
				}
				if(data.id=="showMaxCAD"){
					window.open(location.href);
				}
				layer.msg('得到表格列表的 id：'+ listId +'，下拉菜单 id：'+ data.id);
			}
		});
	});
</script>

<script type="text/javascript">
	let skinStr='layui-layer-lan';

	let flagShowMenu=false;
	function showMenu() {
		if(!flagShowMenu) {
			$("#div_menuContent").show();
			flagShowMenu=true;
		}else{
			$("#div_menuContent").hide();
			flagShowMenu=false;
		}
	}
	function getHomeUrl(){
		let postData={"appkey":"data_home_url"};
		let svgInfo=sensorServer.getSettingsByAppkey(postData);
		if(svgInfo==undefined||svgInfo==null){
			layer.msg("请设置数据后台主页！");
			return;
		}
		if(svgInfo.appval!=undefined&&svgInfo.appval!=null){
			let homeUrl=svgInfo.appval;
			return  homeUrl;
		}
		return  "";
	}
	//1. 显示进入报警数据
	function showWarningList(e){
		let state=e.getAttribute("data-type");
		let url=getHomeUrl()+"/map_warningList.html";  //"http://localhost:9001/map_warningList.html";

		layer.open({
			moveOut:true,
			move:'.layui-layer-title',
			skin:skinStr, // 'layui-layer-lan', // skin: 'layui-layer-demo', //样式类名
			type: 2
			,title: "今日报警" //不显示标题栏
			,closeBtn: 1
			,maxmin:true
			,fixed:false
			,area: ['600px','400px']
			,shade: 0.2
			,id: 'LAY_layuipro' //设定一个id，防止重复弹出
			//,btn: '关闭全部'
			,btnAlign: 'c'
			,move:true
			//,moveType: 0 //拖拽模式，0或者1
			,resize:true
			,anim:1 //弹出动画
			,content:url //'<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">你知道吗？亲！<br>layer ≠ layui<br><br>layer只是作为Layui的一个弹层模块，由于其用户基数较大，所以常常会有人以为layui是layerui<br><br>layer虽然已被 Layui 收编为内置的弹层模块，但仍然会作为一个独立组件全力维护、升级。<br><br>我们此后的征途是星辰大海 ^_^</div>'
		});
	}

	//2. 今日待办
	function showJinRiDaiBan(e) {
		let state=e.getAttribute("data-type");
		let url=getHomeUrl()+"/map_todayThingsList.html";
		layer.open({
			skin:skinStr,
			type: 2
			,title: "今日待办" //不显示标题栏
			,closeBtn: 1
			,maxmin:true
			,fixed:false
			,moveOut:true
			,area:['600px','400px']
			,shade: 0.2
			,id: 'LAY_layuipro' //设定一个id，防止重复弹出
			//,btn: '关闭全部'
			,btnAlign: 'c'
			,move:true
			//,moveType: 0 //拖拽模式，0或者1
			,resize:true
			,content:url //'<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">你知道吗？亲！<br>layer ≠ layui<br><br>layer只是作为Layui的一个弹层模块，由于其用户基数较大，所以常常会有人以为layui是layerui<br><br>layer虽然已被 Layui 收编为内置的弹层模块，但仍然会作为一个独立组件全力维护、升级。<br><br>我们此后的征途是星辰大海 ^_^</div>'
		});
		//全局使用。即所有弹出层都默认采用，但是单个配置skin的优先级更高
		layer.config({
			skin: 'demo-class'
		})
	}

	//3. 显示所有位置
	function showAllLocation(e) {
		let state=e.getAttribute("data-type");
		let url=getHomeUrl()+"/map_sensorList.html?state="+state; //"http://localhost:9001/map_sensorList.html?state="+state;
		layer.open({
			skin:skinStr,
			//skin: 'layui-layer-rim', //加上边框
			type: 2
			,title: "全部安装点" //不显示标题栏
			,closeBtn: 1
			,maxmin:true
			,fixed:false
			,area: ['600px','400px']
			,shade: 0.2
			,id: 'LAY_layuipro' //设定一个id，防止重复弹出
			//,btn: '关闭全部'
			,btnAlign: 'c'
			,move:true
			//,moveType: 0 //拖拽模式，0或者1
			,resize:true
			,anim:1 //弹出动画
			,content:url //'<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">你知道吗？亲！<br>layer ≠ layui<br><br>layer只是作为Layui的一个弹层模块，由于其用户基数较大，所以常常会有人以为layui是layerui<br><br>layer虽然已被 Layui 收编为内置的弹层模块，但仍然会作为一个独立组件全力维护、升级。<br><br>我们此后的征途是星辰大海 ^_^</div>'
		});
	}

	// 4.显示报表
	function showReportList(e){
		let state=e.getAttribute("data-type");
		let url=getHomeUrl()+"/map_reportList.html";
		layer.open({
			skin:skinStr,
			type: 2
			,title: "报表数据" //不显示标题栏
			,closeBtn: 1
			,maxmin:true
			,fixed:false
			,moveOut:true
			,area:['600px','400px']
			,shade: 0.2
			,id: 'LAY_layuipro' //设定一个id，防止重复弹出
			//,btn: '关闭全部'
			,btnAlign: 'c'
			,move:true
			//,moveType: 0 //拖拽模式，0或者1
			,resize:true
			,anim:1 //弹出动画
			,content:url //'<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">你知道吗？亲！<br>layer ≠ layui<br><br>layer只是作为Layui的一个弹层模块，由于其用户基数较大，所以常常会有人以为layui是layerui<br><br>layer虽然已被 Layui 收编为内置的弹层模块，但仍然会作为一个独立组件全力维护、升级。<br><br>我们此后的征途是星辰大海 ^_^</div>'
		});
		//全局使用。即所有弹出层都默认采用，但是单个配置skin的优先级更高
		layer.config({
			skin: 'demo-class'
		})
	}

	//5. 进入后台
	function showTargetDataServer(e) {
		let postData={"appkey":"data_home_url"};
		let svgInfo=sensorServer.getSettingsByAppkey(postData);
		if(svgInfo==undefined||svgInfo==null){
			layer.msg("请设置数据后台主页！");
			return;
		}
		if(svgInfo.appval!=undefined&&svgInfo.appval!=null){
			let homeUrl=svgInfo.appval;
			window.open(homeUrl);
		}
		window.location.href="";
	}

	function showSelectNoteInfo(flag) {
		if(flag==1) {
			$("#modal").show();
		}else{
			$("#modal").hide();
		}
	}
	function showSelectNoteInfo2() {
		customTask();
	}


	//获取屏幕坐标转换CAD 坐标
	// $(document).ready(function(){
	// 	$(document).mousemove(function(e){
	// 		$('#xy').html("X ："+e.pageX+"| Y："+e.pageY);
	// 		const worldPos = gstarSDK.screen2World({x:100, y: 100});
	// 		$('#xy').append("[X ："+worldPos.x+"| Y："+worldPos.y+"]");
	// 	});
	// });

	//修改 批注位置
	function EditDevice(noteinfo) {
		if(noteinfo==null)
			return;
		let arr=noteinfo.content.position.toString().split(',');
		let x=parseFloat(arr[0]).toFixed(2);
		let y=parseFloat(arr[1]).toFixed(2);
		let z=parseFloat(arr[2]).toFixed(2);
		let sensorPid=noteinfo.userName.replace("sensorPid_","");
		let postData={"ledPid":"0","sensorPid":sensorPid,"x":x,"y":y,"z":z};
		sensorServer.updateCoordinate(postData);
	}

	function  showGasInfo(noteinfo) {
		//debugger;
		let sensorPid=noteinfo.userName.replace("sensorPid_","");
		getSensorByPid(sensorPid);
	}
	function getSensorByPid(sensorPid){
		let sensorInfo=sensorServer.getSensorByPid({"sensorPid":sensorPid});
		if(sensorInfo.ch4!=null) {
			$("#table_data_CH4")[0].innerText = sensorInfo.ch4.toFixed(2);
		}
		if(sensorInfo.co2!=null){
			$("#table_data_CO2")[0].innerText=sensorInfo.co2.toFixed(2);
		}
		if(sensorInfo.co!=null){
			$("#table_data_CO")[0].innerText=sensorInfo.co;
		}
		if(sensorInfo.temperature!=null){
			$("#table_data_T")[0].innerText=sensorInfo.temperature.toFixed(1);
		}
		if(sensorInfo.o2!=null){
			$("#table_data_O2")[0].innerText=sensorInfo.o2.toFixed(1);
		}
		if(sensorInfo.humidity!=null){
			$("#table_data_H")[0].innerText=sensorInfo.humidity.toFixed(1);
		}
		$("#table_data_location")[0].innerText=sensorInfo.devicelocation;
		$("#table_data_pid")[0].innerText=sensorPid;
		$("#table_data_lastuploadtime")[0].innerText=sensorInfo.lastDataTime;
	}

</script>
<script type="text/javascript">
	///=====================业务========================================
	//获取设备位置
	function  getSensorListInfo(spacename) {
		let dataList=sensorServer.getSensorList({"page":1,"rows":1000});
		if(dataList==undefined||dataList==null)
		{
			alert("初始化LED设备失败！");
			return "[]";
		}
		let sensorList=dataList.data;
		let arrStr="[";
		for (let i=0;i< sensorList.length;i++){
			let postion= sensorList[i].coordinatex+","+ sensorList[i].coordinatey+",0.0000";
			let obj_sensorPId="sensorPid_"+sensorList[i].pid;
			arrStr+='{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"'+spacename+'","stamp":"rotbot","position":"'+postion+'","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4",' +
					'"noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"'+obj_sensorPId+'"},';
		}
		arrStr=arrStr.substr(0, arrStr.length - 1);
		arrStr+="]";
		return arrStr;
	}

	///=====================业务========================================
	//先判断是否是IE浏览器，IE10及以下的IE浏览器不支持，直接弹出提示告知
	window.onload = function () {
		var browser = getBrowerInfo()
		var ieversion = getIeVersion();
		if (browser == 'IE') {
			if (ieversion != '11.0') {
				alert('不支持IE10及以下的浏览器，请使用其他浏览器打开重试！')
			}
		}
	}
	const hideFunction = {
		notes: [ // 批注
			// 'noteCustomizeLine', // 手绘线
			// 'noteArrow', // 箭头
			// 'noteWord', // 文字
			// 'noteCloudLine', // 云线
			// 'noteImage', // 图片
			// 'noteGuideLine', // 引线
			// 'noteStraightLine', // 直线
			// 'noteRectangle', // 矩形
			// 'noteOval', // 椭圆
			// 'noteCheckView', // 审图
			// 'noteStamp' // 图章
		],
		marks: [], // 书签
		save: [ // 保存
			// 'saveAs', // 另存为
			// 'savePDF', // 另存PDF
			// 'saveImg', // 截图
			// 'print' // 打印
		],
		measures: [ // 测量
			// 'measureLength', // 长度
			// 'measureArea', // 面积
			// 'measureCoordinate', // 坐标
			// 'measureArc', // 弧长
			// 'measureAngle', // 角度
			// 'measureSetProportion' // 设比例
		],
		viewport: [ // 视口相关
			'zoomE', // 显示全图
			'custom', // 窗口缩放
			'fullScreen', // 全屏
			'switchBackground'//切换背景色
		]
	}

	// 初始化SDK
	var gstarSDK = new GStarSDK({
		wrapId: 'webcad',  //容器ID
		switchLayoutCB: switchLayout, // 点击布局功能会触发此回调
		apiHost: window.location.host,  //API域名，转换PDF、另存功能需要向该域名发送请求，如果没有用的转PDF、版本转换功能，则无须关注这个参数。
		tipsTime: 3000, //错误提示信息存在时间(毫秒)，默认3000（3秒）
		mobileSizeLimit: 15 * 1024 * 1024, //移动端可打开ocf文件的最大限制（字节数），默认5242880(5M)
		pcSizeLimit: 30 * 1024 * 1024,  //PC端可打开ocf文件最大限制（字节数），默认12582912(12M)
		sizeLimitCB: sizeLimit, //当ocf文件超过设置的最大值后，执行该回调函数
		language: 'zh', //语言设置，可选'zh'（简中）/'en'(英语)/'ko'(韩语),默认'zh'
		measureAccuracy: 3,  //测量数值的精度位数
		mode: 'default', //填充显示模式，"default":默认值，粗文字不填充，其他填充图案正常填充；"line":所有元素都不填充；"fill":所有需要填充元素都填充
		notesChangeCB: notesChange, //增加、删除、修改批注后的操作函数


		notesSelectCB: notesSelect, //批注点击回调事件，无返回或返回为假值则不进入批注的编辑模式，如果返回为真值则正常进入选中编辑批注模式
		toolbarHideItems: hideFunction, // 隐藏hideFunction里面定义的功能
		isHideMarks: false, //是否隐藏软件自带的书签功能
		hideToolbar: true, // 是否隐藏左侧工具栏
	});



	//1. 加载批注
	// var all = '[{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","linetype":"Continuous","linecolor":7,"lineweight":2,"text":"我是文字","textposition":"1111,11320,0.0000","textcolor":7,"textsize":42.11296969602014,"drawbackground":0,"hatchcolor":11,"rotation":0},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"2","noteType":"HCNoteText","noteVersion":2,"state":1,"userId":0,"userName":"test123"}' +
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","linetype":"Continuous","linecolor":7,"lineweight":2,"text":"我是文字","textposition":"1111,11320,0.0000","textcolor":51,"textsize":42.11296969602014,"drawbackground":0,"hatchcolor":11,"rotation":0},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"2","noteType":"HCNoteText","noteVersion":2,"state":1,"userId":0,"userName":"test456"}' +
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test100"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test101"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test102"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test103"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test104"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test105"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test106"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test107"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test108"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test109"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test110"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test111"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test112"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test112"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test114"} '+
	// 		',{"attachSize":0,"changeCount":0,"content":{"layoutname":"Model","spacename":"1F","stamp":"home","position":"1111,11320,0.0000","data":{"textstamp":""}},"createDate":"","fileId":0,"id":0,"lastModifyDate":"","localId":"4","noteType":"HCNoteStamp","noteVersion":2,"state":1,"userId":0,"userName":"test115"} '+
	// 		']';
	var all;//getSensorList();
	let allObj; //JSON.parse(all);
	function noteshow(spacename){
		//debugger;
		gstarSDK.notes.clear(); //目前只能整体加载所有批注，无法增量添加，所以加载前，需要先清空已有的批注
		if(all==null||all==undefined) {
			let strArr=getSensorListInfo(spacename);
			allObj=JSON.parse(strArr);
			gstarSDK.notes.show(allObj);
		}else{
			gstarSDK.notes.show(allObj);
		}
		//console.log(JSON.parse(all));

		$("li.GStarSDK-func-btn-marks").remove();
		$("li.GStarSDK-func-btn-notes").remove();
		$("li.GStarSDK-func-btn-measures").remove();
		$(".GStarSDK-pc-toolsbar-list").children("li").eq(0).remove();
		$(".GStarSDK-pc-toolsbar-floatbar").remove();//隐藏切换图层
	}
	$(document).ready(function(){

	});
	// 自定义图章定义,图章图片支持base64和url。
	gstarSDK.notes.noteStamp.maps = {
		//rotbot:'../images/robot.png',
		rotbot:'../images/robot33.png',
		home: '',
		dog: '',
		cat: '',
		music: 'https://static.easyicon.net/preview/131/1311243.gif'
	};

	function  customTask() {
		// 自定义图章编辑界面显示的内容，可以将自己的业务逻辑需要显示的内容添加到这里
		var _DOM_Modal_Stamp = document.getElementById('modalstamp')
		_DOM_Modal_Stamp.setAttribute('style', 'display:none')
		var _DOM_Input_Stamp = document.getElementById('inputstamp')
		var _DOM_OK_Stamp = document.getElementById('stampok')
		gstarSDK.notes.noteStamp.detailCB = function (currentData) {
			// 显示弹框，返回当前图章的自定义数据
			_DOM_Modal_Stamp.setAttribute('style', '')
			if (currentData.textstamp) {
				_DOM_Input_Stamp.value = currentData.textstamp
			}
		}
		_DOM_OK_Stamp.onclick = function () {
			var textstamp = _DOM_Input_Stamp.value
			gstarSDK.notes.noteStamp.setData({ textstamp })
			_DOM_Modal_Stamp.setAttribute('style', 'display:none')
			_DOM_Input_Stamp.value = ''
		}

	}


	gstarSDK.enableZoom(5);  // 开启鼠标缩放功能,数字是缩放的速度
	gstarSDK.enablePan(1);    // 开启鼠标平移功能
	// 切换布局回调方法
	function switchLayout(obj) {
		//alert(obj.globalName) //布局名称
		//var makeocfurl = 'http://127.0.0.1/transform.do?fileId=' + fileId + '&layout=' + obj.globalName //根据布局globalName获取相应布局名称，由于布局图形必须有对应的布局名称，后台才能转换生成，需要将布局名传给后台，然后后台返回转换后的ocf地址
		//var layoutocfurl = getLayoutOcfUrl(makeocfurl)

		var layoutocfurl = demoocfurl[String(obj.globalName)] //样例布局ocf文件
		getDrawSheet(layoutocfurl, function (arraybuffer) {
			gstarSDK.render('ocf', arraybuffer, fileId, true);
		});
	}

	// 当ocf文件超过设置的最大值后，执行这个函数，里面逻辑可以自己定义
	function sizeLimit(ocfSize, limitSize) {
		alert('图纸太大，超过了系统设置的最大值')
		//alert('图纸太大，当前图纸大小:' + parseInt(ocfSize / 1048576) + 'M,大于系统限制的：' + parseInt(limitSize / 1048576)+'M')
	}

	//增加、删除、修改批注后的操作函数
	function notesChange(notetype, noteinfo) {
		console.log("批注操作是：" + JSON.stringify(notetype));
		console.log("批注内容是：" + JSON.stringify(noteinfo));
		console.log("批注内容是：");

		//修改
		if(notetype=='modify')
			EditDevice(noteinfo);

		console.log(JSON.stringify(noteinfo));
	}

	function notesSelect(noteData) {
		//如果需要对批注编辑功能进行权限控制，这里写入自己的权限判断逻辑，返回假则用户无法编辑批注，返回真可以正常编辑批注。
		console.log('noteData', noteData);
		showGasInfo(noteData);
		$("#modal").show();
		//return false
		return true;
	}

	//加载图纸==========================

	//测试用的ocf样例文件
	var demoocfurl = {
		'*MODEL_SPACE': 'https://resource-cn.gstarcad.com/sampledraw/0000012863.ocf',
		'*PAPER_SPACE': 'https://resource-cn.gstarcad.com/sampledraw/0000012863.257.ocf',
	}

	var fileId = 1234 //当前图纸的唯一标识

	// 初始化渲染默认ocf文件
	//var defaultocfurl = 'http://127.0.0.1/file/ocf/1001/test1.ocf'  //默认显示的ocf文件url地址
	// var defaultocfurl = demoocfurl['*MODEL_SPACE']
	var defaultocfurl =getCADURL();  //"http://led.longder.com/test.ocf";   "ocf/ningtiaota.ocf"; //

	// getDrawSheet(defaultocfurl, function (arraybuffer) {
	// 	gstarSDK.render('ocf', arraybuffer, fileId, true)
	// })

	getDrawSheet(defaultocfurl, function (arraybuffer) {
		gstarSDK.render('ocf', arraybuffer, fileId, true).then(() => {
			console.log('渲染完成');
			let spanceName=gstarSDK.layoutInfo.m_Handle;
			//debugger;
			noteshow(spanceName);

			$("li.GStarSDK-func-btn-marks").remove();
			$("li.GStarSDK-func-btn-notes").remove();
			$("li.GStarSDK-func-btn-measures").remove();
			$(".GStarSDK-pc-toolsbar-list").children("li").eq(0).remove();
			$(".GStarSDK-pc-toolsbar-floatbar").remove();//隐藏切换图层
		})

	})


	//加载图纸============================

	// 下载图纸数据
	function getDrawSheet(url, cb) {
		var req;
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest()
		} else {
			req = new ActiveXObject('Microsoft.XMLHTTP')
		}
		gstarSDK.Tips.showProgress(0, '加载中...')
		req.onload = function () {
			if ((req.status >= 200 && req.status < 300) || req.status === 304) {
				cb(req.response)
			}
			if (req.status === 404) {
				gstarSDK.Tips.showProgress(0, url + ' 此ocf文件下载失败')
			}
		}
		req.open('GET', url, true)
		req.responseType = 'arraybuffer'
		req.send(null)
	}

	// 获取布局图纸转换请求链接返回的ocf地址
	function getLayoutOcfUrl(url) {
		var req
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest()
		} else {
			req = new ActiveXObject('Microsoft.XMLHTTP')
		}
		req.open('GET', url, false)
		req.send(null)

		req.onreadystatechange = function () {
			if (req.status == 200 && req.readyState == 4) {
				alert(req.responseText)
			}
		}
		return req.responseText
	}

	//获取浏览器信息
	function getBrowerInfo() {
		var userAgent = window.navigator.userAgent.toLowerCase()
		var browserType = ''
		// 浏览器类型IE
		if (userAgent.match(/msie/) != null || userAgent.match(/trident/) != null) {
			browserType = 'IE'
		}
		return browserType
	}

	//获取IE浏览器版本
	function getIeVersion() {
		var IEMode = document.documentMode
		var rMsie = /(msie\s|trident.*rv:)([\w.]+)/;
		var ma = window.navigator.userAgent.toLowerCase()
		var match = rMsie.exec(ma);
		try {
			return match[2];
		} catch (e) {
			return IEMode;
		}
	}

	function getCADURL() {
		let postData = {"appkey": "cad_background"};
		let settingsInfo =sensorServer.getSettingsByAppKey(postData);
		if (settingsInfo != undefined && settingsInfo != null) {
			if (settingsInfo.appval != undefined && settingsInfo.appval != null) {
				if (settingsInfo.appval == "")
					return "";
				return  settingsInfo.appval;
			}
		}
		return  "";
	}
	// 鼠标滚轮事件  向上<0 向下>0
	$('body').on('wheel', function () {
		if (event.deltaY < 0) {
			console.log('鼠标滚轮上划');
		} else if (event.deltaY > 0) {
			console.log('鼠标滚轮下划');
		}
	})

</script>
</html>
